﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Configuration;
using Midapex.SmartOrm;
using Midapex.SmartOrm.Tools.Wizard.Properties;

namespace Midapex.SmartOrm.Tools.Wizard
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        void SetActivePage(int index)
        {
            try
            {
                this.applicationControl.Visible = false;
                this.dataSourceControl.Visible = false;
                this.ormTablesControl.Visible = false;
                this.wizardFace.Visible = false;

                this.buttonPrevious.Enabled = true;
                this.buttonNext.Enabled = true;
                curPage = index;

                switch (index)
                {
                    case 0:
                        this.wizardFace.Visible = true;
                        this.buttonPrevious.Enabled = false;
                        break;
                    case 1:
                        this.applicationControl.Visible = true;
                        break;
                    case 2:
                        this.dataSourceControl.Visible = true;
                        dataSourceControl.ReadAppConfig();
                        break;
                    case 3:
                        this.ormTablesControl.Visible = true;
                        dataSourceControl.WriteAppConfig();
                        
                        ormTablesControl.UpdateOrmClasses();

                        this.buttonNext.Enabled = false;
                        break;
                }
            }
            catch(Exception e)
            {
                MessageBox.Show(this, e.Message, Resources.Warning, 
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                curPage--;
                SetActivePage(curPage);
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            SetActivePage(0);
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buttonPrevious_Click(object sender, EventArgs e)
        {
            curPage--;
            SetActivePage(curPage);
        }

        int curPage = 0;

        private void buttonNext_Click(object sender, EventArgs e)
        {
            curPage++;
            SetActivePage(curPage);
        }
    }
}